package com.wuotng.xsxx.xjxx.service.impl;

import java.util.List;
import com.wuotng.common.utils.DateUtils;
import com.wuotng.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.wuotng.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.wuotng.xsxx.xjxx.domain.XsxxXjxxFj;
import com.wuotng.xsxx.xjxx.mapper.XsxxXjxxMapper;
import com.wuotng.xsxx.xjxx.domain.XsxxXjxx;
import com.wuotng.xsxx.xjxx.service.IXsxxXjxxService;

import static com.wuotng.common.utils.SecurityUtils.*;

/**
 * 学籍信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@Service
public class XsxxXjxxServiceImpl implements IXsxxXjxxService 
{
    @Autowired
    private XsxxXjxxMapper xsxxXjxxMapper;

    /**
     * 查询学籍信息
     * 
     * @param xjxxId 学籍信息主键
     * @return 学籍信息
     */
    @Override
    public XsxxXjxx selectXsxxXjxxByXjxxId(String xjxxId)
    {
        return xsxxXjxxMapper.selectXsxxXjxxByXjxxId(xjxxId);
    }

    /**
     * 查询学籍信息列表
     * 
     * @param xsxxXjxx 学籍信息
     * @return 学籍信息
     */
    @Override
    public List<XsxxXjxx> selectXsxxXjxxList(XsxxXjxx xsxxXjxx)
    {
        return xsxxXjxxMapper.selectXsxxXjxxList(xsxxXjxx);
    }

    /**
     * 新增学籍信息
     * 
     * @param xsxxXjxx 学籍信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertXsxxXjxx(XsxxXjxx xsxxXjxx)
    {
        xsxxXjxx.setCreateTime(DateUtils.getNowDate());

        xsxxXjxx.setXjxxId(IdUtils.fastSimpleUUID());
        xsxxXjxx.setCreateTime(DateUtils.getNowDate());
        xsxxXjxx.setCreateBy(getUsername());
        xsxxXjxx.setUserId(getUserId());
        xsxxXjxx.setDeptId(getDeptId());





        int rows = xsxxXjxxMapper.insertXsxxXjxx(xsxxXjxx);
        insertXsxxXjxxFj(xsxxXjxx);
        return rows;
    }

    /**
     * 修改学籍信息
     * 
     * @param xsxxXjxx 学籍信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updateXsxxXjxx(XsxxXjxx xsxxXjxx)
    {
        xsxxXjxx.setUpdateTime(DateUtils.getNowDate());
        xsxxXjxxMapper.deleteXsxxXjxxFjByXjxxId(xsxxXjxx.getXjxxId());
        insertXsxxXjxxFj(xsxxXjxx);
        return xsxxXjxxMapper.updateXsxxXjxx(xsxxXjxx);
    }

    /**
     * 批量删除学籍信息
     * 
     * @param xjxxIds 需要删除的学籍信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteXsxxXjxxByXjxxIds(String[] xjxxIds)
    {
        xsxxXjxxMapper.deleteXsxxXjxxFjByXjxxIds(xjxxIds);
        return xsxxXjxxMapper.deleteXsxxXjxxByXjxxIds(xjxxIds);
    }

    /**
     * 删除学籍信息信息
     * 
     * @param xjxxId 学籍信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteXsxxXjxxByXjxxId(String xjxxId)
    {
        xsxxXjxxMapper.deleteXsxxXjxxFjByXjxxId(xjxxId);
        return xsxxXjxxMapper.deleteXsxxXjxxByXjxxId(xjxxId);
    }

    /**
     * 新增学籍附件信息
     * 
     * @param xsxxXjxx 学籍信息对象
     */
    public void insertXsxxXjxxFj(XsxxXjxx xsxxXjxx)
    {
        List<XsxxXjxxFj> xsxxXjxxFjList = xsxxXjxx.getXsxxXjxxFjList();
        String xjxxId = xsxxXjxx.getXjxxId();
        if (StringUtils.isNotNull(xsxxXjxxFjList))
        {
            List<XsxxXjxxFj> list = new ArrayList<XsxxXjxxFj>();
            for (XsxxXjxxFj xsxxXjxxFj : xsxxXjxxFjList)
            {
                xsxxXjxxFj.setXjxxId(xjxxId);
                list.add(xsxxXjxxFj);
            }
            if (list.size() > 0)
            {
                xsxxXjxxMapper.batchXsxxXjxxFj(list);
            }
        }
    }
}
